package com.qingcloud.base.context;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.qingcloud.base.remote.pojo.LoginUserDTO;

public class UserContextHolder {

    private static final ThreadLocal<LoginUserDTO> USER_CACHE = new TransmittableThreadLocal<>();

    /**
     * 保存登录用户信息缓存
     */
    public static void setUserInfo(LoginUserDTO loginUserDTO) {
        USER_CACHE.set(loginUserDTO);
    }

    /**
     * 获取登录用户信息
     */
    public static LoginUserDTO getUserInfo() {
        return USER_CACHE.get();
    }

    /**
     * 清空用户登录信息
     */
    public static void clear() {
        USER_CACHE.remove();
    }

}
